<?php
namespace App\Common\Lib\Fun;

use App\Common as com;
use App\Common\Lib\Fun\Html as thisHtml;

class Html {

	/**
	 * 获取去除标记的html
	 * @param $html
	 * @param int|null $maxLen 截取长度。 [null]全部
	 * @return string
	 */
	public static function getPlainTextIntroFromHtml( $html, int $maxLen = null ) {
		// Remove the HTML tags
		$html = strip_tags( $html );
		//
		$html = str_replace( '&nbsp;', '', $html );

		// Convert HTML entities to single characters
/*		$html = html_entity_decode( $html, ENT_QUOTES, 'UTF-8' );
		$html_len = mb_strlen( $html, 'UTF-8' );*/

		// Make the string the desired number of characters
		// Note that substr is not good as it counts by bytes and not characters
		// $html = mb_substr( $html, 0, strlen( $html ), 'UTF-8' );
		if( $maxLen !== null ){
			return mb_substr( $html, 0, $maxLen, 'UTF-8' );
		}
		return $html;
	}

}
